<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>参数传递</title>
  </head>
  <body>
    <div id="root"></div>
  </body>
  <script src="/lib/react.js"></script>
  <script src="/lib/react-dom.js"></script>
  <script src="/lib/babel.js"></script>

  <script type="text/babel">
    class App extends React.Component {
      constructor() {
        super();
        this.state = {
          count: 100,
        };
      }

      // 注意这里使用bind传递的参数event应该在最后接收
      add10(num, e) {
        console.log(e, num);
        const { count } = this.state;
        this.setState({
          count: count + num,
        });
      }
      //   注意这样定义的方法是不能接收自定义参数的，只能接收到event
      add100 = (e) => {
        console.log(e);
      };
      // 这样传递是最好的，顺序一样，自定义参数也可以传递   
      add1000(e,num){
        console.log(e, num);
        const { count } = this.state;
        this.setState({
          count: count + num,
        });
      }
      render() {
        const { count } = this.state;
        return (
          <div>
            <h1>参数传递</h1> 
            <h5>{count}</h5>
            <button onClick={this.add10.bind(this, 10)}>+10</button>
            <button onClick={this.add100}>+100</button>
            <button onClick={(e) => this.add1000(e,1000)}>+1000</button>
          </div>
        );
      }
    }
 
    const rootEl = document.querySelector("#root");
    const root = ReactDOM.createRoot(rootEl);
    root.render(<App />);
  </script>
</html>
